# -*- coding: utf-8 -*-

from apps.common.base import BaseHandler, requires_auth


class AlarmListHandler(BaseHandler):
    """
     告警日志列表 /alarm/list
    """

    @requires_auth
    async def get(self, cuser, *args, **kwargs):

        page = self.get_argument("page", default=1)
        limit = self.get_argument("limit", default=15)
        almtype = self.get_argument("almtype", default=0)
        query = self.get_argument("query", default="")

        alarms = await self.alarm_model.get_alarms(cuser['id'], int(page),
                                                   int(limit), int(almtype), query)
        if alarms:
            l = []
            for a in alarms:
                # del a["tmp.id"]
                l.append(a)

            data = {
                'alarm': l,
            }
            return self.render_json(0, 'ok', data)
        else:
            return self.render_json(-1, "暂无记录")
